<template>
  <div id="sticky">
    <div class="header">
      <div class="left">
        <div class="time">
          <span>{{ timeNow.day }}</span>
          <span>{{ timeNow.month }}</span>
        </div>
        <h1 class="title">知乎日报</h1>
      </div>
      <router-link to="/personal" class="link-btn">
        <img :src="timg" alt="" />
      </router-link>
    </div>
  </div>
</template>

<script>
import timg from "@/assets/images/timg.jpg";
import { formatTime } from "@/assets/utils";
import { reactive } from 'vue'
export default {
  name: "Header",
  setup() {
    const timeNow = reactive({
        month: 0,
        day: 0
    })
    const [month, day] = formatTime(0, "{1}-{2}").split("-");
    timeNow.month = month
    timeNow.day = day
    // const timeNow = () => {
    //   const [month, day] = formatTime(0, "{1}-{2}").split("-");
    //   console.log(month, day);
    //   let area = [
    //     "一月",
    //     "二月",
    //     "三月",
    //     "四月",
    //     "五月",
    //     "六月",
    //     "七月",
    //     "八月",
    //     "九月",
    //     "十月",
    //     "十一月",
    //     "十二月",
    //   ];
    //   return {
    //     day,
    //     month: area[month - 1],
    //   };
    // };
    return {
      timg,
      timeNow,
    };
  },
};
</script>

<style lang="less">
#sticky{
  position: sticky;
  // position: -webkit-sticky;
  background-color: #fff;
  top: 0px;
  width: 100%;
  z-index: 100;
}
.header {
  // height: 80px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  .left {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .time {
      padding-right: 15px;
      border-right: 1px solid #ddd;
      span {
        display: block;
        font-size: 20px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        &:nth-child(2) {
          font-size: 12px;
          height: 15px;
          line-height: 15px;
        }
      }
    }
    .title {
      padding-left: 10px;
      font-size: 22px;
    }
  }
  .link-btn {
    box-sizing: border-box;
    height: 30px;
    width: 30px;
    img {
      display: block;
      height: 100%;
      width: 100%;
      border-radius: 50%;
    }
  }
}
</style>
